﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSqlDatabase>
#include "dbtools.h"
#include "passitem.h"
#include <QStandardItemModel>
#include <QLineEdit>
#include <QCloseEvent>
#include <QSystemTrayIcon>
#include <QSettings>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(Dbtools *tools,QWidget *parent = nullptr);
    ~MainWindow();


private slots:
    void on_treeView_clicked(const QModelIndex &index);
    void newTypeDlg();
    //右键菜单响应函数
    void slotContextMenu(QPoint pos);
    //tree控件的右键槽
    void treeContextMenu(QPoint pos);

    void on_account_pushButton_clicked();

    void on_pass_pushButton_clicked();
    void onSaveNewType(QString tname,QString tid,QString ticon);
    void myTryIconActive(QSystemTrayIcon::ActivationReason);
    void syncAllTypeSuccess();
    void syncAllItemSuccess();
    void syncAllTypeFail(QString);
    void syncAllItemFail(QString);
    void regUserHttpError(QString);
    void showAboutWindow(bool);
    void changeMainPass();
    void test();


public slots:
    void addItemDialog_ok_button_clicked(PassItem *item);


private:
    Ui::MainWindow *ui;
    Dbtools *dbtools;
    QMenu *popMenu;
    QMenu *popTreeMenu;
    //程序的设置信息
    QSettings setting;
    //搜索框
    QLineEdit *searchLineEdit;

    //主界面表格的MOdel
    QStandardItemModel *tableModel;
    //主界面分类的model
    QStandardItemModel *treeModel;

    QSystemTrayIcon *mySysTrayIcon=nullptr;
    QMenu *mySysTrayMenu;
    long long eventTime;


    void updateTableData(QString tid,QList<PassItem*> *list=nullptr);
    void updateTreeData();

    void initTreeView();
    void initTableWidget();
    void initToolButton();
    void initStrutsBar();
    void addStyle();
    void refreshCurrentItemsList();


    //QString getEncodStr(QString);
    //QString getDecodStr(QString);

protected:
    void closeEvent(QCloseEvent *event);
    bool eventFilter(QObject *watched, QEvent *event);
};

#endif // MAINWINDOW_H
